import { dayjs } from 'element-plus';

/**
 * @description: 颜色装换
 * @param {*} value
 * @return {*}
 */
export const colorFormatter = (value: string) => {
  const w = getWeek(value);
  // 假设我们要将'C'这个标签设置为红色
  if (w === '周六' || w === '周日') {
    return 'red';
  } else {
    return 'black'; // 其他标签保持黑色
  }
};

const getWeek = (date?: string) => {
  const dayOfWeek = dayjs(date).day();
  // 将数字转换为周几的字符串
  const daysOfWeek = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
  return daysOfWeek[dayOfWeek];
};

/**
 * @description: 标签装换
 * @param {*} value
 * @return {*}
 */
export const labelFormatter = (value: string, count?: number) => {
  let result = '';
  const SUM = count || 10;
  let length = value.length;

  for (let i = 0; i < length; i += SUM) {
    // 每次截取 4 个字符，并在后面添加换行符
    result += value.substring(i, SUM) + '\n';
  }
  // 移除最后一个多余的换行符
  result.slice(0, -1);

  return result;
};
